/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.dtgenerator.core.rtgen.entitygen.changeserializer.serializer;

import com.inspur.edp.bef.spi.entity.AbstractBizEntityChangeJsonSerializer;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.serializer.changeser.ChangeSerGenContext;
import com.inspur.edp.cef.generator.coreGenerator.base.serializer.changeser.entity.serializer.NodeDataChangeSerClassGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.serializer.changeser.entity.serializer.NodeDataChangeSerGenContext;
import com.inspur.edp.das.commonmodel.IGspCommonObject;

public class BefNodeDataChangeSerGenerator extends NodeDataChangeSerClassGenerator {

    public BefNodeDataChangeSerGenerator(IGspCommonObject object, ChangeSerGenContext edChangeSerGenContext, NodeDataChangeSerGenContext parentSerGenContext) {
        super(object, edChangeSerGenContext, parentSerGenContext);

    }

    @Override
    protected TypeInfo setParentClass() {
        return new TypeInfo(AbstractBizEntityChangeJsonSerializer.class);
    }


    @Override
    protected java.util.ArrayList<ClassMethodGenerator> createConstructorGenerators() {
        return new java.util.ArrayList<ClassMethodGenerator>(java.util.Arrays.asList(
                new ClassMethodGenerator[]{new NodeDataChangeSerCtorGenerator(getName(), isRoot,
                        this.getNodeDataChangeSerGenContext())}));
    }

    @Override
    public NodeDataChangeSerClassGenerator getEntityChangeSerClassGenerator(IGspCommonObject item) {
        return new BefNodeDataChangeSerGenerator(item, ChangeSerGenContext, getNodeDataChangeSerGenContext());
    }

    //    protected override List<ClassMethodGenerator> CreateMethodGenerators()
    //    {
    //        return new List<ClassMethodGenerator>()
    //        {
    //            new NodeDataSerGetTypesGenerator(Context.SerTypes),
    //            new NodeDataChangeGetChildGenerator(Context),
    //            new IsChildObjectCodeGenerator(Context)
    //        };
    //    }

    //    protected override List<BaseGenerator> CreateClassExtendChildGenrators()
    //    {
    //        List<BaseGenerator> list = new List<BaseGenerator>();
    //        var childTypes = GetChildTypes();
    //        foreach (var item in childTypes)
    //        {
    //            list.Add(new NodeDataChangeSerGenerator(item.Value.Key, item.Key, false, item.Value.Value, edChangeSerGenContext, Context));
    //        }
    //        return list;
    //    }

    //    private Dictionary<string, KeyValuePair<List<Type>, List<Type>>> GetChildTypes()
    //    {
    //        Dictionary<string, KeyValuePair<List<Type>, List<Type>>> childTypes = new Dictionary<string, KeyValuePair<List<Type>, List<Type>>>();
    //        foreach (var item in entityTypes)
    //        {
    //            foreach (var prop in EntityUtil.GetProps(item))
    //            {
    //                var childAttributes = prop.GetCustomAttributes(typeof(ChildAttribute), false);
    //                if (childAttributes != null && childAttributes.Length != 0)
    //                {
    //                    ChildAttribute childAttribute = childAttributes[0] as ChildAttribute;
    //                    AddToChildTypes(childTypes, childAttribute.ObjectCode, childAttribute.SerializerType, childAttribute.TargetInterfaceType);
    //                }
    //                var childExtendAttribute = prop.GetCustomAttributes(typeof(ChildExtendAttribute), false);
    //                if (childExtendAttribute != null && childExtendAttribute.Length != 0)
    //                {
    //                    ChildExtendAttribute childExtendAttr = childExtendAttribute[0] as ChildExtendAttribute;
    //                    AddToChildTypes(childTypes, childExtendAttr.ObjectCode, childExtendAttr.SerializerType, childExtendAttr.ObjectType);
    //                }
    //            }

    //        }
    //        return childTypes;
    //    }

    //    private void addToChildTypes(Dictionary<string, KeyValuePair<List<Type>, List<Type>>> childTypes, string childCode, Type serType, Type entityType)
    //    {
    //        KeyValuePair<List<Type>, List<Type>> types;
    //        if (childTypes.ContainsKey(childCode))
    //            types = childTypes[childCode];
    //        else
    //        {
    //            types = new KeyValuePair<List<Type>, List<Type>>(new List<Type>(), new List<Type>());
    //            childTypes.Add(childCode, types);
    //        }
    //        if (serType != null)
    //            types.Key.Add(serType);
    //        if (entityType != null)
    //            types.Value.Add(entityType);
    //    }

}
